package com.platform.destiny.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.platform.destiny.dto.UserPageReq;
import com.platform.destiny.dto.UserReq;
import com.platform.destiny.entity.User;
import com.platform.destiny.mapper.UserMapper;
import com.platform.destiny.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> queryUserList(UserReq req) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .like(StrUtil.isNotBlank(req.getUsername()), User::getUsername, req.getUsername())
                .eq(req.getStatus() != null, User::getStatus, req.getStatus());
        List<User> users = userMapper.selectList(wrapper);
        return users;
    }

    @Override
    public Integer insert(User user) {
        return userMapper.insert(user);
    }

    @Override
    public Integer update(User user) {
        return userMapper.updateById(user);
    }

    @Override
    public Integer deleteById(Long id) {
        return userMapper.deleteById(id);
    }

    @Override
    public User selectById(Long id) {
        return userMapper.selectById(id);
    }

    @Override
    public Page<User> selectUserPage(UserPageReq userReq) {
        return userMapper.queryUserPageList(userReq);
    }
}
